<template>
	 <h2 align="center">修改我的信息</h2>
	 <div v-if="actidx==2">
	    <table align="center" style="font-size: 1.5pc;">
			<td align="center">
				<th>功能:</th>
				<td align="center"> <button v-on:click="go2UpdPwd()">修改密码</button></td>
				<td align="center"><button v-on:click="go2UpdPic()">修改图片</button></td>
			</td>
		</table>
	</div> 
	<!-- 修改密码 -->
	<div v-if="actidx==0" style=" justify-content: space-around; " >
		<table   align="center" style="width: 40%;"> 
		<tr>
			<th>  旧密码：</th>
		 <td><input v-model="pwd.oidPwd"  type="password" /></td>
		</tr>
		 <tr>
		 	<th>  新密码：</th>
		  <td><input v-model="pwd.newPwd" type="password" /></td>
		 </tr>
		 <tr>
		 	<th>二次密码：</th>
		  <td><input v-model="pwd.newPwd2"  type="password" /></td>
		 </tr>
		</table>
		   
   	  
   	  	  
   </div> 
   <!-- 修改图片-->
  <div v-if="actidx==1" style="display: flex; justify-content: space-between;" >
	  <div style="width:10%;"></div>
	  <div style="width:45%; text-align: center;">
		 <h2 >当前图片</h2>
	  <img style="width: 50%;height:15vw;"
	  	v-bind:src="this.$ip +'/api/public/showimg/'+this.$store.state.user.pic">
   </div>
   <div style="width:45%; text-align:center;">
	   <p>图片: <input type="file" ref="img"> </p>
   </div>
   </div> 
<hr />
   <div v-if="actidx!=2" style="display: flex; justify-content: space-between;">
	
			<p>&nbsp;</p>
		   	<p><button v-on:click="save()">确定</button></p>
		   	<p> <button v-on:click="saveout()">取消</button></p>
		   	<p>&nbsp;</p>
		   </div>
</template>

<script>
	export default {
	
		name: 'Updeate',
	
		data() {
			return {
				pic:this.$store.state.user.pic,
				pwd:{oidPwd:"",newPwd:"",newPwd2:""},
				bShow:false,
				role:this.$store.state.user.role,
				actmsg:['修改密码','修改头像','显示'],
				actidx:2 
			}
		},
		methods: {	
			go2UpdPic(){
			 this.actidx=1;},
			go2UpdPwd(){
			 this.actidx=0;},
		    save(){
				console.log(this.$store.state.user)
				console.log(this.role)
				     // var rloe=this.$store.state.user.rloe
				if(this.actidx==1){ //修改头像
				var fd = new FormData;
				var file = this.$refs.img.files[0];
					fd.append("mypic", file);
			this.$postf("/api/user/updatePic", fd).then((resp) => {
			this.$store.state.user.pic = resp.data.data + "?x=" + (new Date().getMilliseconds());
			    console.log("修改成功")   
		})
}
				if(this.actidx==0){ //修改密码
				console.log("0000000000000")
				console.log(this.pwd)
				this.pwd.oidPwd=parseInt(this.pwd.oidPwd)
				this.pwd.newPwd=parseInt(this.pwd.newPwd)
				this.pwd.newPwd2=parseInt(this.pwd.newPwd2)
				if(this.pwd.newPwd==null) return
				if(this.oldPwd==this.pwd.newPwd) return
				if(this.pwd.newPwd==this.pwd.newPwd2){
					let objpwd={oldPwd: this.pwd.oidPwd,newPwd:this.pwd.newPwd}
					console.log("22222")
					this.$postx("/api/user/updatePwd", objpwd).then((resp)=>{
			            console.log(resp.data.data)
						

					  this.$store.state.user= {
								name:"",
								rloe:'',
								rloename:"",
								token:'',
								pic:''};
							
						window.localStorage.setItem("token","")
						this.$router.push('/Login')
						
						
						})
				}
				
				}
			},
			saveout() {
				this.actidx = 2;
			},
	
		},
		}
		
</script>

<style>
</style>